package ModelLayer;
import java.util.HashMap;


/**
 * Write a description of class PersonContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PersonContainer
{
    // instance variables - replace the example below with your own
    private HashMap<Integer, Person> persons;
    private static PersonContainer instance;
    /**
     * Constructor for objects of class PersonContainer
     */
    private PersonContainer()
    {
        // initialise instance variables
        persons = new HashMap<Integer, Person>();
    }
    public static PersonContainer getInstance()
    {
        if(instance == null)
        {
            instance = new PersonContainer();
        }
        return instance;
    }    


    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public void createPerson(Person person)
    {
        if(person instanceof RegisteredCustomer)

                {
                RegisteredCustomer updPerson = (RegisteredCustomer)person;
                persons.put(updPerson.getPhoneNumber(),person);
                }
        if(person instanceof Employee)
                {
                Employee updPerson = (Employee)person;
                persons.put(updPerson.getPhoneNumber(),person);
                }
                
            
    }
    
    
    public Person findPerson(int phoneNumber)
     {
         return persons.get(phoneNumber);
     }
        
     public void deletePerson(int phoneNumber)
     {
        persons.remove(phoneNumber);   
     }
    
     public void updatePersonName(int phoneNumber, String name)
        {
            persons.get(phoneNumber).setName(name);
        }
        
     public void updatePersonPhoneNumber(int phoneNumber, int newPhoneNumber)
        {
       
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {
                RegisteredCustomer updPerson = (RegisteredCustomer)persons.get(phoneNumber);
                updPerson.setPhoneNumber(newPhoneNumber);
                persons.remove(phoneNumber);
                persons.put(newPhoneNumber, updPerson);
                
                }
        if(persons.get(phoneNumber) instanceof Employee)
                {
                Employee updPerson = (Employee)persons.get(phoneNumber);
                updPerson.setPhoneNumber(newPhoneNumber);
                persons.remove(phoneNumber);
                persons.put(newPhoneNumber, updPerson);                
                }
        }
        
        public void updatePersonAddress(int phoneNumber, String address)
        {
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {
                RegisteredCustomer updPerson = (RegisteredCustomer)persons.get(phoneNumber);
                updPerson.setAddress(address);
                
                }
        if(persons.get(phoneNumber) instanceof Employee)
                {
                Employee updPerson = (Employee)persons.get(phoneNumber);
                updPerson.setAddress(address);             
                }
        }  
        public void updatePersonCity(int phoneNumber, String city)
        {
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {
                RegisteredCustomer updPerson = (RegisteredCustomer)persons.get(phoneNumber);
                updPerson.setCity(city);
                
                }
        if(persons.get(phoneNumber) instanceof Employee)
                {
                Employee updPerson = (Employee)persons.get(phoneNumber);
                updPerson.setCity(city);             
                }
        }        
        
        public void updatePersonZIPCode(int phoneNumber, int ZIPCode)
        {
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {
                RegisteredCustomer updPerson = (RegisteredCustomer)persons.get(phoneNumber);
                updPerson.setZIPCode(ZIPCode);
                
                }
        if(persons.get(phoneNumber) instanceof Employee)
                {
                Employee updPerson = (Employee)persons.get(phoneNumber);
                updPerson.setZIPCode(ZIPCode);             
                }
        }          
        
        
        public void updatePersonMaxCredit(int phoneNumber, int maxCredit)
        {
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {
                RegisteredCustomer updPerson = (RegisteredCustomer)persons.get(phoneNumber);
                updPerson.setMaxCredit(maxCredit);
                
                }
        if(persons.get(phoneNumber) instanceof Employee)
                {            
                }
        }          
        
        public void updatePersonUserLevel(int phoneNumber, int userLevel)
        {
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {
                
                }
        if(persons.get(phoneNumber) instanceof Employee)
                {
                Employee updPerson = (Employee)persons.get(phoneNumber);
                updPerson.setUserLevel(userLevel);             
                }
        } 
        
        public void updatePersonLoginName(int phoneNumber, String loginName)
        {
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {
                }
        if(persons.get(phoneNumber) instanceof Employee)
                {
                Employee updPerson = (Employee)persons.get(phoneNumber);
                updPerson.setLoginName(loginName);             
                }
        }         
        
        public void updatePersonPassword(int phoneNumber, String password)
        {
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {
                
                }
        if(persons.get(phoneNumber) instanceof Employee)
                {
                Employee updPerson = (Employee)persons.get(phoneNumber);
                updPerson.setPassword(password);             
                }
        }           
        
        public void updatePersonPayment(int phoneNumber, int payment)
        {
        if(persons.get(phoneNumber) instanceof RegisteredCustomer)

                {

                }
        if(persons.get(phoneNumber) instanceof Employee)
                {
                Employee updPerson = (Employee)persons.get(phoneNumber);
                updPerson.setPayment(payment);             
                }
        }           
    }
 